package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.mall.commons.exception.ExceptionProcessorUtils;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.converter.ProductCateConverter;
import com.cskaoyan.shopping.dal.entitys.ItemCat;
import com.cskaoyan.shopping.dal.persistence.ProductCateMapper;
import com.cskaoyan.shopping.dto.AllProductCateResponse;
import com.cskaoyan.shopping.dto.ProductCateDto;
import com.cskaoyan.shopping.service.IProductCateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther: wubang
 * @description:
 * @date: 2022-07-09 15:42
 */
@Service
public class IProductCateServiceImpl implements IProductCateService {
    @Autowired
    ProductCateMapper productCateMapper;

    @Autowired
    ProductCateConverter productCateConverter;
    @Override
    public AllProductCateResponse getAllProductCate() {

        AllProductCateResponse response = new AllProductCateResponse();

        try {
            List<ItemCat> itemCats = productCateMapper.selectAll();
            List<ProductCateDto> productCateDtos = productCateConverter.items2Dto(itemCats);
            //执行成功
            response.setCode(ShoppingRetCode.SUCCESS.getCode());
            response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
            response.setProductCateDtoList(productCateDtos);
        } catch (Exception e) {
            e.printStackTrace();
            ExceptionProcessorUtils.wrapperHandlerException(response,e);
        }
        return response;
    }
}
